<?php
class BlacklistsController extends AppController {

    var $name = 'Blacklists';
    var $helpers = array('Html', 'Form');

    function admin_index() {
        $this->Blacklist->recursive = 0;
        $this->set('blacklists', $this->paginate());
    }

    function admin_add() {
        if (!empty($this->data)) {
            $this->Blacklist->create();
            if ($this->Blacklist->save($this->data)) {
                $this->Session->setFlash(__('The Blacklist has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Blacklist could not be saved. Please, try again.', true));
            }
        }
    }

    function admin_edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid Blacklist', true));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->Blacklist->save($this->data)) {
                $this->Session->setFlash(__('The Blacklist has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Blacklist could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Blacklist->read(null, $id);
        }
    }

    function admin_delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for Blacklist', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->Blacklist->del($id)) {
            $this->Session->setFlash(__('Blacklist deleted', true));
            $this->redirect(array('action'=>'index'));
        }
    }

    function admin_delete_blacklists() {
        if($this->Blacklist->deleteAll(array('Blacklist.id'=>$this->data['BlacklistsDelete']))) {
            $this->Session->setFlash(__('IP addresses deleted successfully',true));
        } else {
            $this->Session->setFlash(__('IP addresses deleted error. Try again!',true));
        }
        $this->redirect(array('action'=>'index'), null, true);
    }

}
?>